/*
 * @(#)NoticeBOImpl.java $version 2012-8-10
 * 
 * Copyright 2012 NADOSTAR Gruop. All rights Reserved.
 * NADOSTAR PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nadostar.iims.etc.bo.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.nadostar.extensions.util.DataMap;
import com.nadostar.iims.etc.bo.NoticeBO;
import com.nadostar.iims.etc.dao.NoticeDAO;
import com.nadostar.iims.model.Notice;

/**
 * The Class NoticeBOImpl.
 * 
 * @author Lixing
 *
 */
@Service("NoticeBO")
@Transactional(readOnly = true)
public class NoticeBOImpl implements NoticeBO {
	private static Log log = LogFactory.getLog(NoticeBOImpl.class);
	
	@Autowired
	private NoticeDAO noticeDAO = null;
	
	public List<DataMap> getNoticeList(String ntcTypeCd, String delYn, int offset, int count) {
		List<DataMap> result = new ArrayList<DataMap>();
		try {
			result = noticeDAO.selectNoticeList(ntcTypeCd, delYn, offset, count);
		} catch (Exception e) {
			log.error(e, e);
			return new ArrayList<DataMap>();
		}
		return result;
	}

	public int getNoticeListCount(String ntcTypeCd, String delYn) {
		try {
			return noticeDAO.selectNoticeListCount(ntcTypeCd, delYn);
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
	}

	public Notice getNoticeDetail(int ntcSeq) {
		Notice result = new Notice();
		try {
			result = noticeDAO.selectNoticeDetail(ntcSeq);
		} catch (Exception e) {
			log.error(e, e);
			return new Notice();
		}
		return result;
	}

	@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
	public boolean saveOrUpdate(Notice notice) {
		int result;
		try {
			if(notice.getNtcSeq() > 0) {
				result = noticeDAO.updateNotice(notice);
			} else {
				result = noticeDAO.insertNotice(notice);
			}
		} catch (Exception e) {
			log.error(e, e);
			return false;
		}
		return result > 0 ? true : false;
	}

}
